import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import MaDictRadio from "@/components/ma-dict-picker/ma-dict-radio.vue";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import { concat } from "lodash-es";
import { rdOrganizeProjLineStatusDictData } from "./common.tsx";
import { page as getZoneList } from "@/plugins/ai-warning/organization/api/rdOrganizeZone.ts";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: "项目名称",
      prop: "name",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "项目名称" }),
        maxlength: 50,
      },
      itemProps: { rules: [{ required: true, message: "请输入项目名称" }] },
    },
    {
      label: "所属区域",
      prop: "zone_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getZoneList,
        apiParams: {
          page: 1,
          pageSize: 1000,
        },
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((zone: any) => ({
              label: zone.name,
              value: zone.id,
            }));
          }
          return [];
        },
        placeholder: t("form.pleaseSelect", { msg: "所属区域" }),
        filterable: true,
        clearable: true,
      },
      itemProps: { rules: [{ required: true, message: "请选择所属区域" }] },
    },
    {
      label: "排序",
      prop: "sort",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "排序" }),
        min: -2147483648,
        max: 2147483647,
      },
      itemProps: { rules: [{ required: true, message: "请输入排序" }] },
      defaultValue: 0,
    },
    {
      label: "状态",
      prop: "status",
      render: () => MaDictRadio,
      renderProps: {
        multiple: false,
        data: rdOrganizeProjLineStatusDictData(),
      },
      itemProps: { rules: [{ required: true, message: "请选择状态" }] },
      defaultValue: 1,
    },
    {
      label: "备注",
      prop: "remark",
      render: "input",
      renderProps: {
        type: "textarea",
        placeholder: t("form.pleaseInput", { msg: "备注" }),
        rows: 3,
      },
    },
  ]);
}
